package com.sservice.base.utils;

import com.alibaba.druid.util.DruidPasswordCallback;
import org.apache.commons.lang3.StringUtils;

import java.util.Properties;

/**
 * Created by suweiming on 2018/3/8.
 */
public class DBPasswordCallback extends DruidPasswordCallback {
    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        String pwd = properties.getProperty("password");
        String key = properties.getProperty("key");
        if (StringUtils.isNoneBlank(pwd)) {
            try {
                String password = MyEncrypt.desDecrypt(pwd, key != null ? key : MyEncrypt.KEY_DES);
                setPassword(password.toCharArray());
            } catch (Exception e) {
                setPassword(pwd.toCharArray());
            }
        }
    }

    private String decrypt(String src) {
        //解密
        return MyEncrypt.desDecrypt(src);
    }

}